package it.fuesi.synotools.model.base;

import it.fuesi.synotools.constants.ApiErrorCode;
import it.fuesi.synotools.constants.ApiErrorKey;

/**
 * Created by pascotto on 16/10/14.
 */
public class ErrorObject {

    private int code;
    private String message;
    private ApiErrorCode errorCode;



    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    private String key;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
        errorCode = ApiErrorCode.get(code);

    }

    public void setMessage(String message){
        this.message = message;
    }

    public String getMessage(){
        if(message != null) return message;

        if(errorCode == null && code > 0)
            errorCode = ApiErrorCode.get(code);

        if(key != null)
            return ApiErrorKey.get(key).getErrorMessage();

        return errorCode.getErrorMessage();
    }
}
